#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e3+10;
const int inf = 0x3f3f3f3f;

typedef struct {int v,w,nxt;}edge;

int h[MAXN],now[MAXN],d[MAXN],k,n,m,cnt = 1,s,t,maxflow;
edge e[MAXN*40];

void link(int x,int y,int w){
	e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;
	e[++cnt] = (edge){x,0,h[y]};h[y] = cnt;
}

bool bfs(){
	memset(d,0,sizeof(d));
	d[s] = 1,now[s] = h[s];
	queue<int> q;
	q.push(s);
	while(q.size()){
		int x = q.front();q.pop();
		for(int i = h[x];i;i = e[i].nxt){
			int y = e[i].v;
			if(!d[y] && e[i].w){
				now[y] = h[y];
				d[y] = d[x] + 1;
				q.push(y);
				if(y == t) return 1;
			}
		}
	}
	return 0;
}

int dinic(int x,int flow){
	if(x == t) return flow;
	int res = flow;
	for(int i = now[x];i && res;i = e[i].nxt){
		int y = e[i].v;now[x] = i;
		if(e[i].w && d[y] == d[x] + 1){
			int k = dinic(y,min(res,e[i].w));
			if(!k) d[y] = 0;
			res -= k;
			e[i].w -= k;
			e[i^1].w += k;
		}
	}
	return flow - res;
}

int main (){
	scanf("%d %d",&k,&n);
	s = 0;t = k+n+1;
	for(int i = 1;i <= k;i++){
		int x;scanf("%d",&x); m+=x;
		link(s,i,x);
	}
	for(int i = 1;i <= n;i++){
		int p ;scanf("%d",&p);
		while(p--){
			int x;scanf("%d",&x);
			link(x,i+k,1);
		}
		link(i+k,t,1);
	}
	int flow;
	while(bfs()) while(flow = dinic(s,inf)) maxflow += flow;
	if(maxflow != m) return puts("No Solution!"),0;
	for(int i = 1;i <= k;i++){
		printf("%d: ",i);
		for(int j = h[i];j;j = e[j].nxt){
			int y = e[j].v;
			if(!e[j].w && y != t && y != s){
				printf("%d ",y-k);
			}
		}
		puts("");
	}
	return 0;
}
